﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;

namespace PJOnimal
{
    public class Man2 : GameScene
    {
        public Matrix camera; //máy quay nè anh hai :$
        Vector3 toaDocamera; //tọa độ ca camera dù vector3 nhưng thật ra cũng là vector2 thôi :$

        public Character nhanVat;
        public Background HinhNen;
        public MapGame mapGame;
        SpriteFont font;
        
        

        public Man2(Onimal game)
            : base(game)
        {
            nhanVat = new Character(game);
            font = game.Content.Load<SpriteFont>("Font/Font1");
            HinhNen = new Background(game, nhanVat.toaDoNhanVat);
            mapGame = new MapGame(game);
            mapGame.LoadMap(game);
            
        }

        public override void Update(GameTime gameTime)
        {
            
            nhanVat.Update(gameTime, mapGame, toaDocamera.X);
            
            if (nhanVat.mySprite.Y > 600)
                game.dieuHanhGame.ChuyenMan(game.dieuHanhGame.man2, game.dieuHanhGame.end);
            //HinhNen = new Background(game, nhanVat.toaDoNhanVat);
            //mapGame = new MapGame(game);
            //mapGame.LoadMap(); 
            HinhNen.UpdateFlag(gameTime);
            //mapGame.UpdateEnemy();
            mapGame.UpdateEnemy(gameTime, nhanVat.mySprite.X);
            mapGame.UpdateXYEnemy(gameTime, nhanVat);
            base.Update(gameTime);
        }

        public override void Draw(SpriteBatch spriteBatch)
        {
            //sửa sao
            
            spriteBatch.DrawString(font, "toa Do Nhan Vat " + nhanVat.toaDoNhanVat, Vector2.Zero, Color.Black); //test
            spriteBatch.DrawString(font, "Nhan vat da chon " + (game.NhanVatSelect + 1), new Vector2(0,30), Color.Black); //test
            spriteBatch.DrawString(font, "toadocamera: " + toaDocamera.X, new Vector2(200, 50), Color.Black);
            spriteBatch.DrawString(font, "jump: " + nhanVat .jump , new Vector2(200, 80), Color.Black);
            base.Draw(spriteBatch);
        }

        //cái gì dính trên màn hình (giao diện) thì draw ở trên, còn cái gì trong ma trận phải draw ở dưới đây! :$
        public void DrawTrongMaTran(GameTime gameTime)
        {
            HinhNen.Draw(game.spriteBatch); 
            nhanVat.Draw(game.spriteBatch);
            mapGame.Draw(game.spriteBatch);

            if (toaDocamera.X <= 0 && nhanVat.mySprite.FlagAction < 3 && toaDocamera.X > -nhanVat.toaDoNhanVat.X + 350)
                toaDocamera = new Vector3(-nhanVat.toaDoNhanVat.X + 350, 0, 0);
            //if (toaDocamera.X > camera.)
            //    return;
            if (toaDocamera.X > 0)
                toaDocamera.X = 0;
            if (toaDocamera.X < -7200) //chiều rộng của ma trận
                toaDocamera.X = -7200;

            camera = Matrix.CreateTranslation(toaDocamera);
        }
    }
}
